<?php

namespace App\Admin\Renderable;

use App\Admin\Repositories\Jobposition;
use App\Admin\Repositories\Plaza;
use App\Models\CategoryModel;
use App\Models\CompanyModel;
use App\Models\JobpositionModel;
use App\Models\PlazaModel;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use SuperEggs\DcatDistpicker\DcatDistpickerHelper;

class AreaTab extends LazyRenderable
{

    public function grid(): Grid
    {
        return Grid::make(new Plaza(['jobPositionInfo']), function (Grid $grid) {
            $grid->model()->where('cur_type',PlazaModel::TYPE_AREA)->orderBy('sort');
            $grid->column('id')->sortable();
            $grid->column('cur_type')->using(PlazaModel::TYPE_LIST)->label([
                PlazaModel::TYPE_JOB_POSITION => 'blue1',
                PlazaModel::TYPE_AREA => 'orange2',
            ]);
            $grid->column('name')->display(function () {
                if ($this->cur_type == PlazaModel::TYPE_JOB_POSITION) {
                    return $this->jobPositionInfo->position_name;
                }
                return $this->name;
            });
            $grid->column('images')->image('', 100, 100);
            $grid->column('area_images','专区图片')->image('', 100, 100);
            $grid->column('tags')->display(function ($tags) {
                if (!$tags){
                    return '';
                }
                return implode('|', $tags);
            });
            $grid->column('cur_status','状态')->switch();
            $grid->column('updated_at')->sortable();
            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->select('cur_type', '类型', PlazaModel::TYPE_LIST);
            });
            $grid->disableEditButton();
            $grid->showQuickEditButton();
            $grid->disableViewButton();
            $grid->disableDeleteButton();
            $grid->disableActions();
            // 禁用过滤器按钮
            $grid->disableFilterButton();
        });
    }
}